package com.woniuxy.Factory;

import com.woniuxy.entity.Person;

import javax.annotation.Resources;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import static java.lang.Class.forName;

/**
 * @author LinKe
 * @version 1.0
 * @date 2021/11/9 16:06
 *
 * 第三代工厂模式  通过读取配置文件的方式获取对象
 */
public class ThreeFactory {



    public Person doPerson(){
        Properties p =  new Properties();
        String method  = "";
        Person person = null;

        try {
            InputStream is = ThreeFactory.class.getClassLoader().getResourceAsStream("Person.properties");
            p.load(is);
            method = p.getProperty("method");
            person = (Person) Class.forName(method).newInstance();

            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


        return person;
    }



}
